﻿<style type="text/css">
    .auto-style1 {
        width: 400px;
    }

    .easyui-textbox {
        width: 430px;
    }

    .auto-style2 {
        width: 150px;
    }

    .easyui-combobox {
        width: 430px;
    }
</style>
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>项目立项</title>
    <link href="~/css/css_1.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../../easyUI/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../easyUI/themes/icon.css">
    <script type="text/javascript" src="../../easyUI/jquery.min.js"></script>
    <script type="text/javascript" src="../../easyUI/jquery.easyui.min.js"></script>
    <script>

        $(function () {
            jiazai();
            xiala1();
            sel("房屋用途", "house_Purpose");
            sel("建成年代来源", "yers_Source");
            sel("报告类型", "presentation_Type");
            //勘察员
            jsel(2, "survey");
            //估价员
            jsel(3, "evaluation");
        })

        function jiazai() {
            $.ajax({
                url: "http://localhost:25744/api/Project?User_Id=1",
                type: "get",
                dataType: "json",
                success: function (data1) {
                    var msg = eval(data1);
                    $('#dg').datagrid('loadData', msg);
                    $('#dg').datagrid('pagination', true);
                }
            })
        }

        //字典下拉方法
        function sel(name, id) {
            $.ajax({
                url: "http://localhost:25744/api/Dictionary?Dictionary_Type=" + name,
                dataType: "json",
                type: "get",
                success: function (obj) {
                    var data = eval(obj);
                    $("#" + id + "").combobox({
                        data: data,
                        valueField: 'dictionary_Id',
                        textField: 'dictionary_Name',
                        editable: false
                    })
                }
            })
        }
        //角色下拉方法
        function jsel(name, id) {
            $.ajax({
                url: "http://localhost:25744/api/User?Roles_id=" + name,
                dataType: "json",
                type: "get",
                success: function (obj) {
                    var data = eval(obj);
                    $("#" + id + "").combobox({
                        data: data,
                        valueField: 'Users_Id',
                        textField: 'Users_Name',
                        editable: false
                    })
                }
            })
        }
        //所属部门
        function xiala1() {
            $.ajax({
                url: "http://localhost:25744/api/Department?Dictionary_Type=所属部门",
                dataType: "json",
                type: "get",
                success: function (obj) {
                    var data = eval(obj);
                    $("#the_Department").combobox({
                        data: data,
                        valueField: 'department_Id',
                        textField: 'department_Name',
                        editable: false
                    })
                }
            })
        }

        function add() {
            var surplus_Years = $("#surplus_Years").val();
            var basic_Quota = $("#basic_Quota").val();
            var house_Located = $("#house_Located").val();
            var house_Time = $("#house_Time").val();
            var issue_Time = $("#issue_Time").val();
            var basic_Acreage = $("#basic_Acreage").val();
            var projectNumber = "2017002";

            var str = "";
            $(":checkbox:checked").each(function () {
                str += $(this).val() + ",";
            })
            var assessment = str.substr(0, str.length - 1);
            var yers_Source = $("#yers_Source").combobox('getValue');

            var the_Department = $("#the_Department").combobox('getValue');
            var presentation_Type = $("#presentation_Type").combobox('getValue');
            var house_Purpose = $("#house_Purpose").combobox('getValue');
            var survey = $("#survey").combobox('getValue');
            var evaluation = $("#evaluation").combobox('getValue');

            var loan_Name = $("#loan_Name").val();
            var loan_IdCard = $("#loan_IdCard").val();
            var loan_TEL = $("#loan_TEL").val();
            var loan_Contacts = $("#loan_Contacts").val();
            var loan_ContactsTEL = $("#loan_ContactsTEL").val();

            $.ajax({
                url: "http://localhost:25744/api/Project",
                type: "post",
                data: { projectNumber: projectNumber, surplus_Years: surplus_Years, basic_Quota: basic_Quota, house_Located: house_Located, house_Purpose: house_Purpose, house_Time: house_Time, yers_Source: yers_Source, presentation_Type: presentation_Type, the_Department: the_Department, survey: survey, evaluation: evaluation, issue_Time: issue_Time, basic_Acreage: basic_Acreage },
                success: function (data) {
                    if (data != 0) {
                        $.ajax({
                            url: "http://localhost:25744/api/Loan_Info",
                            type: "post",
                            async: false,
                            data: { loan_Name: loan_Name, loan_IdCard: loan_IdCard, loan_TEL: loan_TEL, loan_Contacts: loan_Contacts, loan_ContactsTEL: loan_ContactsTEL, projectNumber: data },
                            success: function (qwe) {
                                if (qwe > 0) {
                                    alert('添加成功');
                                    $('#w').window('close');
                                    jiazai();
                                }
                                else {
                                    alert("添加失败1");
                                }
                            }
                        });
                    }
                    else {
                        alert(添加失败);
                    }
                },
                error: function (e) {
                    alert("错误！！");
                }
            })
        }

        //点击下拉框即可展开
        $(".combo").click(function () {
            if ($(this).prev().combobox("panel").is(":visible")) {
                $(this).prev().combobox("hidePanel");
            } else {
                $(this).prev().combobox("showPanel");
            }
        })

        //显示添加窗口
        function tian() {
            $("#tian").show();
            $("#xiu").hide();
            $('#w').window('open');
        }

        function formatOper(val, row, index) {
            var s = "<a href='#' onclick='editUser(" + row.basic_id + ",\"" + row.projectNumber + "\",\"" + row.surplus_Years + "\",\"" + row.basic_Quota + "\",\"" + row.house_Located + "\",\"" + row.house_Purpose + "\",\"" + row.house_Time + "\",\"" + row.yers_Source + "\",\"" + row.assessment + "\",\"" + row.presentation_Type + "\",\"" + row.the_Department + "\",\"" + row.survey + "\",\"" + row.evaluation + "\",\"" + row.basic_State + "\",\"" + row.issue_Time + "\",\"" + row.survey_StartTime + "\",\"" + row.survey_EndTime + "\",\"" + row.basic_Evaluation + "\",\"" + row.basic_ValueTime + "\",\"" + row.basic_UnitPrice + "\",\"" + row.basic_Acreage + "\",\"" + row.basic_Total + "\",\"" + row.basic_Excl + "\",\"" + row.basic_Enclosure + "\",\"" + row.basic_CreateTime + "\",\"" + row.User_Id + "\")'>修改</a> <a href='#' onclick='delUser(" + row.basic_id + ")'>删除</a>";

            return s;
        }

        //修改反填
        function editUser(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26) {
            $('#w').window('open');

            $("#basic_id").textbox("setValue", i1);
            $("#projectNumber").textbox("setValue", i2);
            $("#surplus_Years").textbox("setValue", i3);
            $("#basic_Quota").textbox("setValue", i4);
            $("#house_Located").textbox("setValue", i5);
            $("#house_Purpose").combobox("setValue", i6);
            $("#house_Time").textbox("setValue", i7);
            $("#yers_Source").combobox("setValue", i8);
            $("#assessment").textbox("setValue", i9);
            $("#presentation_Type").combobox("setValue", i10);
            $("#the_Department").combobox("setValue", i11);
            $("#survey").combobox("setValue", i12);
            $("#evaluation").combobox("setValue", i13);
            $("#basic_State").textbox("setValue", i14);
            $("#issue_Time").textbox("setValue", i15);
            $("#survey_StartTime").textbox("setValue", i16);
            $("#survey_EndTime").textbox("setValue", i17);
            $("#basic_Evaluation").textbox("setValue", i18);
            $("#basic_ValueTime").textbox("setValue", i19);
            $("#basic_UnitPrice").textbox("setValue", i20);
            $("#basic_Acreage").textbox("setValue", i21);
            $("#basic_Total").textbox("setValue", i22);
            $("#basic_Excl").textbox("setValue", i23);
            $("#basic_Enclosure").textbox("setValue", i24);
            $("#basic_CreateTime").textbox("setValue", i25);
            $("#User_Id").textbox("setValue", i26);
            $("#tian").hide();
            $("#xiu").show();

        }

        //删除操作
        function delUser(id) {
            if (confirm('确定删除吗')) {
                $.ajax({
                    url: "http://localhost:25744/apis/Project/Delete?id=" + id,
                    type: "Delete",
                    success: function (obj) {
                        if (obj > 0) {
                            alert('删除成功');
                            jiazai();
                        }
                        else {
                            alert("删除失败");
                        }
                    }
                })
            }
        }

        //修改操作
        function upt() {
            var surplus_Years = $("#surplus_Years").val();
            var basic_Quota = $("#basic_Quota").val();
            var house_Located = $("#house_Located").val();
            var house_Time = $("#house_Time").val();
            var issue_Time = $("#issue_Time").val();
            var projectNumber = "2017002";

            var str = "";
            $(":checkbox:checked").each(function () {
                str += $(this).val() + ",";
            })
            var assessment = str.substr(0, str.length - 1);
            var yers_Source = $("#yers_Source").combobox('getValue');

            var the_Department = $("#the_Department").combobox('getValue');
            var presentation_Type = $("#presentation_Type").combobox('getValue');
            var house_Purpose = $("#house_Purpose").combobox('getValue');
            var survey = $("#survey").combobox('getValue');
            var evaluation = $("#evaluation").combobox('getValue');

            var loan_Name = $("#loan_Name").val();
            var loan_IdCard = $("#loan_IdCard").val();
            var loan_TEL = $("#loan_TEL").val();
            var loan_Contacts = $("#loan_Contacts").val();
            var loan_ContactsTEL = $("#loan_ContactsTEL").val();

            $.ajax({
                url: "http://localhost:25744/api/Project",
                type: "post",
                data: { projectNumber: projectNumber, surplus_Years: surplus_Years, basic_Quota: basic_Quota, house_Located: house_Located, house_Purpose: house_Purpose, house_Time: house_Time, yers_Source: yers_Source, presentation_Type: presentation_Type, the_Department: the_Department, survey: survey, evaluation: evaluation, issue_Time: issue_Time },
                success: function (data) {
                    if (data != 0) {
                        $.ajax({
                            url: "http://localhost:25744/api/Loan_Info",
                            type: "Put",
                            async: false,
                            data: { loan_Name: loan_Name, loan_IdCard: loan_IdCard, loan_TEL: loan_TEL, loan_Contacts: loan_Contacts, loan_ContactsTEL: loan_ContactsTEL, projectNumber: data },
                            success: function (qwe) {
                                if (qwe > 0) {
                                    alert('修改成功');
                                    $('#w').window('close');
                                    jiazai();
                                }
                                else {
                                    alert("修改失败1");
                                }
                            }
                        });
                    }
                    else {
                        alert(修改失败);
                    }
                },
                error: function (e) {
                    alert("错误！！");
                }
            })
        }

    </script>

</head>
<body class="bb1">

    <div title="列表" style="padding:10px;height:100%">
        <div>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="tian()">添加项目</a>
            <select class="easyui-combobox" name="language"><option value="ar">Arabic</option></select>
            <select class="easyui-combobox" name="language"><option value="ar">Arabic</option></select>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px">查询</a>
        </div>
        <table class="easyui-datagrid" title="列表显示" style="width:80%;height:auto"
               data-options="singleSelect:true,collapsible:true" id="dg">
            <thead>
                <tr>
                    <th data-options="field:'basic_id',width:80,align:'center'">项目号</th>
                    <th data-options="field:'projectNumber',width:80,align:'center'">项目编号</th>
                    <th data-options="field:'the_Department',width:80,align:'center'">所属部门</th>
                    <th data-options="field:'loan_Name',width:80,align:'center'">借款人</th>
                    <th data-options="field:'loan_TEL',width:100,align:'center'">借款人联系电话</th>
                    <th data-options="field:'basic_Quota',width:80,align:'center'">借款额度</th>
                    <th data-options="field:'basic_CreateTime',width:150,align:'center'">登记日期</th>
                    <th data-options="field:'basic_State',width:80,align:'center'">项目状态</th>
                    <th data-options="field:'_operate',width:80,align:'center',formatter:formatOper">操作</th>
                </tr>
            </thead>
        </table>

    </div>
    <div id="w" class="easyui-window" title="项目信息" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:60%;height:95%;padding:10px;">
        <form id="ff" method="post">
            <table cellpadding="5">
                <tr hidden="hidden">
                    <td class="auto-style2">项目号:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_Name" id="basic_id" data-options="required:true">
                    </td>
                </tr>
                <tr hidden="hidden">
                    <td class="auto-style2">项目编号:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_Name" id="projectNumber" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">借款人姓名:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_Name" id="loan_Name" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">身份证号:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_IdCard" id="loan_IdCard" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">借款人联系电话:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_TEL" id="loan_TEL" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">联系人:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_Contacts" id="loan_Contacts" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">联系人联系电话:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="loan_ContactsTEL" id="loan_ContactsTEL" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">房屋剩余年限:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="surplus_Years" id="surplus_Years" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">贷款額度（万元）:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="basic_Quota" id="basic_Quota" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">房屋坐落:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="house_Located" id="house_Located" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">房屋用途:</td>
                    <td class="auto-style1">
                        <select id="house_Purpose" name="house_Purpose" style="width:100%" class="combo"></select>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">建筑面积:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" type="text" name="house_Located" id="basic_Acreage" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">建成年代:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" id="house_Time" type="text" name="house_Time" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">建成年代来源:</td>
                    <td class="auto-style1">
                        <select id="yers_Source" name="yers_Source" style="width:100%" class="combo"></select>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">报告类型:</td>
                    <td class="auto-style1">
                        <select id="presentation_Type" name="presentation_Type" style="width:100%" class="combo"></select>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">评估受理</td>
                    <td class="auto-style1">
                        <input id="cbox1" type="checkbox" name="assessment" value="审核评估登记表" />审核评估登记表
                        <input id="cbox2" type="checkbox" name="assessment" value="身份证明" />身份证明
                        <input id="cbox3" type="checkbox" name="assessment" value="房屋权属" />房屋权属
                        <input id="cbox4" type="checkbox" name="assessment" value="网签合同" />网签合同
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">所属部门:</td>
                    <td class="auto-style1">

                        <select id="the_Department" name="the_Department" style="width:100%" class="combo"></select>

                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">勘察员:</td>
                    <td class="auto-style1">

                        <select id="survey" name="survey" style="width:100%" class="combo"></select>

                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">估价员:</td>
                    <td class="auto-style1">

                        <select id="evaluation" name="evaluation" style="width:100%" class="combo"></select>

                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">评估通知单出具日期:</td>
                    <td class="auto-style1">
                        <input class="easyui-textbox" id="issue_Time" type="text" name="issue_Time" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="add()" id="tian">添加</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="upt()" id="xiu" hidden="hidden">修改</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#w').window('close')">取消</a>
                    </td>
                </tr>
            </table>
        </form>

    </div>


</body>
</html>
